package com.wei.frame.presenter;

import androidx.annotation.Nullable;

import com.wei.frame.contract.SplashContract;
import com.wei.frame.di.scope.ActivityScope;
import com.wei.frame.mvp.BasePresenter;

import javax.inject.Inject;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;

/**
 * 作者:赵若位
 * 时间:2021/6/30 15:41
 * 功能:
 */
@ActivityScope
public class SplashPresenter extends BasePresenter<SplashContract.View, SplashContract.Model> {

    @Inject
    public SplashPresenter(@Nullable SplashContract.View view, SplashContract.Model model) {
        super(view, model);
    }

    public void getNewsData() {
        single(getModel().getNewsData("top"))
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(data -> {
                    if (null != data && null != getView()) {
                        getView().onShowNewsData(data.getResult().getData());
                    }
                }, throwable -> {
                    if (null != getView()) {
                        getView().alert(throwable.getMessage());
                    }
                });
    }
}
